var form = document.getElementById('assignUser');

form.onsubmit = function(e) {
	e.preventDefault();
	var request = [];
	var users = [];
	var tests = [];

	for (var i = 0, ii = form.length; i < ii; ++i) {
		var input = form[i];

		if (input.name) {
			if (input.checked) {
				users.push(input.value);
			}

		}
	}

	var tableRows = document.getElementsByClassName('assignTest');
	for (var i = 0; i < tableRows.length; i++) {
		if (tableRows[i].checked) {
			tests.push(tableRows[i].value);
		}
	}	

	for (var i = 0; i < users.length; i++) {
		for (var j = 0; j < tests.length; j++) {
			
			var assign = {};
			assign.user = users[i];
			assign.testId = tests[j];
			request.push(assign);
			
			
		}
	}
	
	var finalRequest = {};
	finalRequest.pairs = request;
	finalRequest = JSON.stringify(finalRequest);
	$.ajax({
		type : 'POST',
		url : $("#assignUser").attr('action'),
		data : finalRequest,
		success : function(msg) {
			console.log(msg);
			document.write(msg);
		}
	});
};
